package Demo;

import java.io.*;

public class Demo64 {
    private static final File FILE = new File("D:\\test\\copy\\buff.Member1");

    public static void main(String[] args)throws Exception {
        saveObject(new Member1("saxon", 18));
        System.out.println(getObject());

    }

    private static void saveObject(Object obj) throws Exception {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(FILE));
        oos.writeObject(obj);
        oos.close();
    }

    private static Object getObject() throws Exception {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(FILE));
        Object obj = ois.readObject();
        ois.close();
        return obj;
    }
}

class Member1 implements Serializable {
    private  String name;
    private int age;

    public Member1(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}